package com.intelligencesoft.pss.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import com.intelligencesoft.pss.entity.base.PageBean;
import com.intelligencesoft.pss.entity.publish.PublishInfo;


@Repository
public class PublishInfoDao extends BaseDao<PublishInfo>{
	
	public List<PublishInfo> findPublishInfoPageData(PublishInfo publishInfo,PageBean pageBean ){
		final String hql = "from PublishInfo p where p.userInfo.id='"+publishInfo.getUserInfo().getId()+"'";
		int pageSize = pageBean.getPageSize();
		int pageNumber = pageBean.getPageNumber();
		Query q = this.getSession().createQuery(hql);
		 if (pageNumber != 0 && pageSize != 0) {
             q.setFirstResult((pageNumber - 1) * pageSize);
             q.setMaxResults(pageSize);
         }
		List<PublishInfo> publishInfos = (List<PublishInfo>)q.list();
        return publishInfos;
	}
	
	public Integer publishCount(PublishInfo publishInfo){
		String hql = "select count(p.id) from PublishInfo p where p.userInfo.id = '" + publishInfo.getUserInfo().getId() +"'";
		Query query = this.getSession().createQuery(hql);
		return Integer.parseInt(query.uniqueResult().toString());
	}
}
